package cn.hd.shop_springboot.controller;

import cn.hd.shop_springboot.mapper.CategoryMapper;
import cn.hd.shop_springboot.mapper.ChinaMapper;
import cn.hd.shop_springboot.pojo.Category;
import cn.hd.shop_springboot.pojo.China;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RestController;

import javax.servlet.http.HttpServletRequest;
import java.util.List;

@RestController
public class IndexController {

    @Autowired
    CategoryMapper categoryMapper;

    @Autowired
    ChinaMapper chinaMapper;

//    @GetMapping("/index")
//    public String toIndex(){
//        return "index";
//    }

    @GetMapping("/category")
    public Category toIndex(){
//        List<Category> category = categoryMapper.selectCategory();
        Category category = categoryMapper.selectCategory1();
        return category;
    }

    @GetMapping("/china")
    public China china(){
//        List<Category> category = categoryMapper.selectCategory();
        China china = chinaMapper.selectByPrimaryKey(0);
        return china;
    }

    @RequestMapping(value = {"/welcome","/do"},name = "欢迎页",method = RequestMethod.GET)
    public String welcome(){
        return "success";
    }

    /**
     * @author c语言中文网
     * @RequestMapping 注解 params 属性
     */
    @RequestMapping(value = "/testParam", params = {"name=springmvc", "url=http://c.biancheng.net"})
    public String params() {
        return "param";
    }

    /**
     * @author c语言中文网
     * @RequestMapping 注解 headers 属性
     */
    @RequestMapping(value = "/testHeader", headers = {"Content-Type=application/json", "Referer=http://c.biancheng.net"})
    public String headers() {
        return "header";
    }

    @RequestMapping("/getpara1")
    public String getPatamter(HttpServletRequest request){
        request.getParameter("name");
        return "success";
    }

    @RequestMapping("/test")
    public String test(String name, String language) {
        System.out.println("a：" + a);
        System.out.println("b：" + b);
        return "success";
    }
    @RequestMapping("/testRequestParam")
    public String testRequestParam(@RequestParam("name") String username, @RequestParam("pass") String password) {
        System.out.println(username + "," + password);
        return "success";
    }
}


